package org.oos.atom.elements;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.oos.atom.entries.OosEntry;
import org.oos.atom.entries.impl.ReviewEntryImpl;
import org.oos.atom.entries.impl.SiteEntryImpl;
import org.oos.util.AtomDate;

import com.google.api.client.util.Key;

/**
 * Is the abstract definition of the entries that are used by 11870 extending
 * the Atom entry format.
 * 
 * @author pablo.gonzalez@11870.com
 * @see ReviewEntryImpl
 * @see SiteEntryImpl
 */
public abstract class AbstractOosEntry implements OosEntry, Cloneable {

	private static final long serialVersionUID = -8080309739320522011L;
	
	@Key
	protected String id = "http://11870.com";

	@Key
	protected Text title = new Text("");

	@Key
	protected String updated = AtomDate.toString(new Date());
	protected Date updatedDate;

	@Key
	protected Text summary = new Text("");

	@Key
	protected AuthorElement author;

	@Key
	protected Text content = new Text("");

	@Key("link")
	protected List<Link> links;

	@Key("category")
	protected List<Category> categories = new ArrayList<Category>();

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.oos.datasource.feed.Entry#getSummary()
	 */
	@Override
	public Text getSummary() {
		return summary;
	}
	
	@Override
	public void setSummary(Text summary) {
		this.summary = summary;
	}
	
	@Override
	public Text getTitle() {
		return title;
	}
	
	@Override
	public void setTitle(Text title) {
		this.title = title;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.oos.atom.entries.OOSEntry#getUpdated()
	 */
	@Override
	public Date getUpdated() {
		if (updatedDate == null) {
			updatedDate = new AtomDate(updated);
		}
		return updatedDate;
	}
	
	@Override
	public void setUpdated(Date updated) {
		this.updatedDate = updated;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.oos.atom.entries.OOSEntry#getAuthor()
	 */
	@Override
	public Author getAuthor() {
		return author;
	}
	
	@Override
	public void setAuthor(Author author) {
		if (author instanceof AuthorElement) {
			this.author = (AuthorElement) author;
		} else {
			this.author = new AuthorElement(author);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.oos.atom.entries.OOSEntry#getContent()
	 */
	@Override
	public Text getContent() {
		return content;
	}
	
	@Override
	public void setContent(Text content) {
		this.content = content;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.oos.atom.entries.OOSEntry#getLinks()
	 */
	@Override
	public List<Link> getLinks() {
		return links;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.oos.atom.entries.OOSEntry#getCategories()
	 */
	@Override
	public List<Category> getCategories() {
		return categories;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#clone()
	 */
	@Override
	public AbstractOosEntry clone() throws CloneNotSupportedException {
		return (AbstractOosEntry) super.clone();
	}

}
